package com.foton.lotterydomain.activity.service.stateflow.event;

import com.foton.lotterycommon.common.Constants;
import com.foton.lotterycommon.common.Result;
import com.foton.lotterydomain.activity.service.stateflow.AbstractState;
import org.springframework.stereotype.Component;

/**
 * @Author RenPu
 * @Date 2023/12/1 17:53
 * @Version 1.0
 * @Description: 活动通过 -具体实现类
 **/

@Component
public class PassState extends AbstractState {

    // 审核通过状态单据，可以执行的流程节点为：审核拒绝，审核关闭，审核执行中

    @Override
    public Result arraignment(Long activityId, Enum<Constants.ActivityState> currentState) {
        return Result.buildErrorResult("审核通过状态不可重复提审！！！！");
    }

    @Override
    public Result checkPass(Long activityId, Enum<Constants.ActivityState> currentState) {
        return Result.buildErrorResult("审核通过状态不可重复审核通过！！！！");
    }

    @Override
    public Result checkRefuse(Long activityId, Enum<Constants.ActivityState> currentState) {
        boolean updateResult = activityRepository.alterStatus(activityId, currentState, Constants.ActivityState.REFUSE);
        return updateResult ? Result.buildResult(Constants.ResponseCode.SUCCESS.getCode(), "活动审核拒绝完成！！！！") : Result.buildErrorResult("活动状态变更失败");

    }

    @Override
    public Result checkRevoke(Long activityId, Enum<Constants.ActivityState> currentState) {
        return Result.buildErrorResult("审核通过不可撤销(可先拒绝审核)！！！！");
    }

    @Override
    public Result open(Long activityId, Enum<Constants.ActivityState> currentState) {
        return Result.buildErrorResult("审核通过状态不可开启！！！！");
    }

    @Override
    public Result close(Long activityId, Enum<Constants.ActivityState> currentState) {
        boolean updateResult = activityRepository.alterStatus(activityId, currentState, Constants.ActivityState.CLOSE);
        return updateResult ? Result.buildResult(Constants.ResponseCode.SUCCESS.getCode(), "活动关闭完成！！！！") : Result.buildErrorResult("活动状态变更失败");
    }

    @Override
    public Result doing(Long activityId, Enum<Constants.ActivityState> currentState) {
        boolean updateResult = activityRepository.alterStatus(activityId, currentState, Constants.ActivityState.DOING);
        return updateResult ? Result.buildResult(Constants.ResponseCode.SUCCESS.getCode(), "活动变更执行中完成！！！！") : Result.buildErrorResult("活动状态变更失败");
    }
}
